package com.zj.osm.adapter

import android.app.AlertDialog
import android.content.Context
import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.RecyclerView
import com.zj.osm.App
import com.zj.osm.R
import com.zj.osm.entity.greendao.Equipment
import com.zj.osm.utils.Configuration
import com.zj.osm.utils.view_utils.*
import com.zj.utils.data.LiveDataBus
import kotlinx.android.synthetic.main.activity_eq_cementproducts.view.*

/**
 * <pre>
 *     author : luhenchang
 *     e-mail : 1276998208@qq.com
 *     time   : 2020/07/20
 *     desc   : 版权所有
 *     version: 1.0
 * </pre>
 */
class CementProductAdapter(context: Context, list: List<Equipment>, cid: Long, id: Long) : RecyclerView.Adapter<CementProductAdapter.MyRecyclerHolder?>() {
    private val mContext: Context = context
    private val list: List<Equipment> = list
    private val cid = cid
    private val id = cid
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CementProductAdapter.MyRecyclerHolder {
        val view: View = LayoutInflater.from(mContext).inflate(R.layout.activity_eq_cementproducts, null);
        return MyRecyclerHolder(view)
    }

    override fun getItemCount(): Int {
        return list.size
    }

    inner class MyRecyclerHolder(rootView: View) : RecyclerView.ViewHolder(rootView) {
        var mTextView: TextView = rootView.equ_tv_name
        var mContent: TextView = rootView.equ_ed_lever
        var delete: TextView = rootView.equ_btn_delete
        var equ_tv_xuan: TextView = rootView.equ_tv_xuan
    }

    @RequiresApi(Build.VERSION_CODES.N)
    override fun onBindViewHolder(viewHolder: CementProductAdapter.MyRecyclerHolder, position: Int) {
        viewHolder.mTextView.text = list[position].name
        viewHolder.mContent.text = list[position].threeName
        viewHolder.delete.setOnClickListener {
            val views = View.inflate(mContext, R.layout.activity_map_dialog, null)
            val dialog = AlertDialog.Builder(mContext).create()
            dialog.setView(views)
            dialog.show()
            val map_btn_quxiao = views.findViewById<Button>(R.id.map_btn_quxiao)
            val map_btn_queding = views.findViewById<Button>(R.id.map_btn_queding)
            map_btn_queding.setOnClickListener { view12: View? ->
                dialog.dismiss()
                App.getInstances().daoSession.equipmentDao.delete(list[position])
                when (list[position].qubie) {
                    5 -> LiveDataBus.get().getChannel(Configuration.BoxChangeWindow).value = 1
//                    6 -> LiveDataBus.get().getChannel(Configuration.PullLineWindow).value = 1
//                    7 -> LiveDataBus.get().getChannel(Configuration.BoxChangeWindow).value = 1
//                    ///水泥制品
//                    8 -> LiveDataBus.get().getChannel(Configuration.ShowCementProductsWindow).value = 1
//                    ///柱上设备
//                    9 -> LiveDataBus.get().getChannel(Configuration.PoleTransformerPopUpWindow).value = 1
//                    10 -> LiveDataBus.get().getChannel(Configuration.PullLineWindow).value = 1
//                    11 -> LiveDataBus.get().getChannel(Configuration.PullLineWindow).value = 1
                }
            }
            map_btn_quxiao.setOnClickListener { dialog.dismiss() }
        }
        viewHolder.equ_tv_xuan.setOnClickListener {
            when (list[position].qubie) {
                5 -> {
                    val alertDialogss = BoxBxChangeWindow(mContext).setContentViewId(R.layout.activity_equ_fsss_dialog).setmapParameters(5, cid, id, list[position])
                    alertDialogss.pop()
                }
//                6 -> {
//                   val alertDialogss = PullLineWindow(mContext).setContentViewId(R.layout.activity_equ_lx_dialog).setmapParameters(6, cid, id, list[position])
//                   alertDialogss.pop()
//               }
//               10 -> {
//                   val alertDialogss = ColumnEquipmentWindow(mContext).setContentViewId(R.layout.activity_equ_zssb_dialog).setmapParameters(10, cid, id, list[position])
//                   alertDialogss.pop()
//               }
//               7 -> {
//                   val alertDialogss = BoxChangeWindow(mContext).setContentViewId(R.layout.activity_equ_fsss_dialog).setmapParameters(7, cid, id, list[position])
//                   alertDialogss.pop()
//               }
//               8 -> {//附属设施
//                   val alertDialogss = ShowCementProductsWindow(mContext).setContentViewId(R.layout.activity_equ_snzp_dialog).setmapParameters(8, cid, id, list[position])
//                   alertDialogss.pop()
//               }
//               9 -> {//变压器
//                   val alertDialogss = PoleTransformerPopUpWindow(mContext).setContentViewId(R.layout.alert_poletransformer_popwindow).setmapParameters(9, cid, id, list[position])
//                   alertDialogss.pop()
//               }
//               11 -> {//柱上制品
//                   val alertDialogss = ColumnAttachmentWindow(mContext).setContentViewId(R.layout.alert_columnattachment_layout).setmapParameters(11, cid, id, list[position])
//                   alertDialogss.pop()
//               }
            }

        }

    }
}